package com.zjsru.plan2024.oneday;

/**
 *  最长特殊序列 II
 * @Author: cookLee
 * @Date: 2024-06-17
 */
public class FindLUSlength {

    /**
     * 主
     * \
     * 输入: strs = ["aba","cdc","eae"]
     * 输出: 3
     * \
     * 输入: strs = ["aaa","aaa","aa"]
     * 输出: -1
     * \
     * @param args args
     */
    public static void main(String[] args) {
        FindLUSlength findLUSlength = new FindLUSlength();
        String[] strs = new String[]{"aabbcc", "aabbcc","c"};
        System.out.println(findLUSlength.findLUSlength(strs));
    }

    /**
     * 查找luslength:双指针枚举
     *
     * @param strs strs
     * @return int
     */
    public int findLUSlength(String[] strs) {
        int len = strs.length;
        int ans = -1;
        for (int i = 0; i < len; i++) {
            String preStr = strs[i];
            boolean check = true;
            for (int j = 0; j < len; j++) {
                String currStr = strs[j];
                //计算是否满足条件
                if (i != j && this.helper(preStr, currStr)) {
                    check = false;
                    break;
                }
            }
            if (check) {
                ans = Math.max(ans, preStr.length());
            }
        }
        return ans;
    }

    /**
     * 子类计算助手类:判断是否满足preStr的子串，如果独有的子串则返回false
     *
     * @param preStr  预str
     * @param currStr 电流强度
     * @return boolean
     */
    private boolean helper(String preStr, String currStr) {
        int preLen = 0;
        int currLen = 0;
        while (preLen < preStr.length() && currLen < currStr.length()) {
            if (preStr.charAt(preLen) == currStr.charAt(currLen)) {
                preLen++;
            }
            currLen++;
        }
        return preLen == preStr.length();
    }


}
